package com.aliyun.dao;


import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.aliyun.bean.QueryPara;
import com.aliyun.util.GetUUID;

@Component("userDao")
@Transactional
public class UserDao extends CommonDao{
	
	public int insertUser(Map<String, Object> map)throws SQLException{
		int a = this.getSqlSession().insert("com.aliyun.dao.UserMapper.insertUser",map);
		String[] areas = (map.get("areas")+"").split(",");
		if(areas!=null && areas.length>0){
			for(String areacode:areas){
				map.put("id", GetUUID.getId());
				map.put("areacode", areacode);
				this.getSqlSession().insert("com.aliyun.dao.UserMapper.insertUserArea",map);
			}
		}
		//areas
		return a;
	}
	public int insertYuMingList(List<Map<String,String>> list)throws SQLException{
		int i = 0;
		for(Map<String,String> map : list){
			i+=this.getSqlSession().insert("com.aliyun.dao.UserMapper.insertYuMing",map);
		}
		return i;
	}
	public int updateYuMingStatus(Map<String, String> map)throws SQLException{
		return this.getSqlSession().insert("com.aliyun.dao.UserMapper.updateYuMingStatus",map);
	}
	public List<Map<String, Object>> getUserItem(QueryPara qp)throws SQLException{
        return this.getSqlSession().selectList("com.aliyun.dao.UserMapper.getUserItem",qp);
    }
	public List<Map<String, Object>> getYuMingTime()throws SQLException{
        return this.getSqlSession().selectList("com.aliyun.dao.UserMapper.getYuMingTime");
    }
	public Map<String, Object> getUserOne(Map<String,String> map)throws SQLException{
        return this.getSqlSession().selectOne("com.aliyun.dao.UserMapper.getUserOne",map);
    }
	public int deleteUser(Map<String, Object> map)throws SQLException{
		this.getSqlSession().delete("com.aliyun.dao.UserMapper.deleteUserArea",map);
		return this.getSqlSession().delete("com.aliyun.dao.UserMapper.deleteUser",map);
	}
}
